package com.cloud.pole.shop.biz.order;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.shop.model.entity.order.ShopOrder;
import com.cloud.pole.shop.model.entity.order.ShopOrderComment;
import com.cloud.pole.shop.model.entity.order.ShopOrderCommentAdmin;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

import com.cloud.pole.mapper.order.ShopOrderCommentMapper;
/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ShopOrderCommentBiz extends BaseBiz<ShopOrderCommentMapper, ShopOrderComment> {
	
	@Autowired
	ShopOrderCommentMapper shopOrderCommentMapper;
	
	public ShopOrderComment selectByPrimaryKey(Long commentId) {
		return super.selectById(commentId);
	}
	
	public ShopOrderComment selectByOrderSn(String orderSn) {
		ShopOrderComment entity = new ShopOrderComment();
		entity.setOrderSn(orderSn);
		return super.selectOne(entity);
	}
	
	@Override
	public void insertSelective(ShopOrderComment msg) {
		super.insertSelective(msg);
	}
	
	public List<ShopOrderComment> selectOrderCommentListByGoodsId(Integer goodsId, String commentType){
		 Example example = new Example(ShopOrderComment.class);
		 Criteria criteria = example.createCriteria();
         example.setOrderByClause("comment_time desc");
		 criteria.andEqualTo("goodsId", goodsId);
		 criteria.andEqualTo("deleteFlag", ShopOrderComment.DELETE_FLAG_NO);
		 //差评
		 if(StringUtils.equals(commentType, ShopOrderComment.COMMENT_TYPE_BAD)) {
			 criteria.andBetween("starNum", ShopOrderComment.STAR_NUM_ONE, ShopOrderComment.STAR_NUM_TWO);
		 }
		 //中评
		 if(StringUtils.equals(commentType, ShopOrderComment.COMMENT_TYPE_COMMON)) {
			 criteria.andEqualTo("starNum", ShopOrderComment.STAR_NUM_THREE);
		 }
		 //好评
		 if(StringUtils.equals(commentType, ShopOrderComment.COMMENT_TYPE_GOOD)) {
			 criteria.andBetween("starNum", ShopOrderComment.STAR_NUM_FOUR, ShopOrderComment.STAR_NUM_FIVE);
		 }
		 return selectByExample(example);		
	}

	public List<ShopOrderCommentAdmin> selectPageShopOrderCommentAdminList(Map<String, Object> map) {
		return shopOrderCommentMapper.selectPageShopOrderCommentAdminList(map);
	}
}
